﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ExpressionTree
{
    /// <summary>
    /// 逻辑运算符
    /// </summary>
    public class OperateSymbol
    {
        /// <summary>
        /// 节点类型转运算符
        /// </summary>
        /// <param name="nodeType"></param>
        public static string Name2Symbol(string nodeType)
        {
            switch (nodeType.ToUpper())
            {
                case "ORELSE": return "OR";
                case "ANDALSO": return "AND";
                case "EQUAL": return "=";
                case "NOTEQUAL": return "!=";
                case "GREATERTHANOREQUAL": return ">=";
                case "GREATERTHAN": return ">";
                case "LESSTHAN": return "<";
                case "LESSTHANOREQUAL": return "<=";
                case "ADD": return "+";
                case "DIVIDE": return "/";
                case "DIVIDEASSIGN": return "/=";
                case "MODULO": return "%";
                case "MULTIPLY": return "*";
                default: return nodeType;
            }
        }

        /// <summary>
        /// 方法到 运算符
        /// </summary>
        /// <param name="fieldName"></param>
        /// <param name="methodName"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public static string Method2Symbol(string fieldName,string methodName,string[] param)
        {
            switch (methodName.ToUpper())
            {
                case "CONTAINS": 
                    return string.Format("{0} in ({1})", fieldName, string.Join(",", param));
                default:
                    return string.Format("{0} {1} {2}", fieldName,methodName, string.Join(",", param));
            }
        }
    }
}
